#include <stdlib.h>
#include <string.h>

#include "vdp.h"

char pattern_table[2048] = { 0 };
char name_table[768] = { 0 };
char color_table[32] = { 0 };
char sprite_pattern_table[2048] = { 0 };
char sprite_attribute_table[64] = { 0 };
struct vdp_device vdp_dev;

void on_vblank()
{   
}

int main()
{
    for (uint16_t i = 0; i < 2048; i++)
        pattern_table[i] = 0xFF;

    for (uint16_t i = 0; i < 768; i++)
        name_table[i] = i % 256;

    color_table[0] = 0x9F;
    color_table[1] = 0x3F;
    color_table[2] = 0x1F;
    color_table[3] = 0xBF;
    color_table[4] = 0xCF;
    color_table[5] = 0xDF;
    color_table[6] = 0xFF;
    color_table[7] = 0x4F;
    color_table[8] = 0x3F;
    color_table[9] = 0xDF;
    color_table[10] = 0xCF;
    color_table[11] = 0xDF;
    color_table[12] = 0xAF;
    color_table[13] = 0xEF;
    color_table[14] = 0x4F;
    color_table[15] = 0xAF;
    color_table[16] = 0x7F;

    color_table[17] = 0x7F;
    color_table[18] = 0xAF;
    color_table[19] = 0x4F;
    color_table[20] = 0xEF;
    color_table[21] = 0xAF;
    color_table[22] = 0xDF;
    color_table[23] = 0xCF;
    color_table[24] = 0xDF;
    color_table[25] = 0x3F;
    color_table[26] = 0x4F;
    color_table[27] = 0xFF;
    color_table[28] = 0xDF;
    color_table[29] = 0xCF;
    color_table[30] = 0xBF;
    color_table[31] = 0x1F;

    // init vdp
    struct vdp_context ctx;
    ctx.mode = VDP_GRAPHIC_MODE_1;
    ctx.size = VDP_SIZE_8_8;
    ctx.mag = VDP_MAG_OFF;
    ctx.interrupt_handler = on_vblank;
    vdp_init(&vdp_dev, &ctx);

    vdp_dev.fill_pattern_table(pattern_table, sizeof(pattern_table));
    vdp_dev.fill_color_table(color_table, sizeof(color_table));
    vdp_dev.fill_name_table(name_table, sizeof(name_table));
    vdp_dev.fill_sprite_attribute_table(sprite_attribute_table, sizeof(sprite_attribute_table));
    vdp_dev.fill_sprite_pattern_table(sprite_pattern_table, sizeof(sprite_pattern_table));

    for (;;);
    return 0;
}